﻿using NHibernate.Criterion;
using System.Collections.Generic;
using NHibernate;
using TeamCommunitySolution.Domain.DataLayer.Base;
using TeamCommunitySolution.Services.Factories;

namespace TeamCommunitySolution.Services.Repositories.Impl
{

    public class GenderRepository : IGenderRepository
    {

        private GenderRepository()
        {
            
        }

        public IList<Gender> GenderList()
        {
            using (ISession session = NHSessionFactory.Factory.OpenSession())
            {
                ICriteria crit = session.CreateCriteria(typeof(Gender));
                crit.AddOrder(Order.Asc("Name"));
                return crit.List<Gender>();
            }
        }

        public Gender Get(string id)
        {
            using(ISession session = NHSessionFactory.Factory.OpenSession())
            {
                Gender gender = session.Get<Gender>(id);
                return gender;
            }
        }

        public static IGenderRepository Instance
        {
            get
            {
                if(_instance == null)
                    _instance = new GenderRepository();

                return _instance;

            }
        }

        private static IGenderRepository _instance;
    }
}
